#ifndef GRID_H
#define GRID_H

#include <cstdio>
#include "igrid.h"

using namespace std;

class Grid :public IGrid
{
public:


    Grid()
    {
    }

    ~Grid()
    {
    }


    shared_ptr<IGrid> copy()
    {

        auto g=make_shared<Grid>();
        int sizeH=sceneHeight/Tile::TILE_SIZE;
        int sizeW=sceneWidth/Tile::TILE_SIZE;
        for (int i = 0; i < sizeH; ++i)
        {
            g->tiles.push_back(std::vector<shared_ptr<Tile>>(sizeW));
            for(int j=0;j<sizeW;++j)
                g->tiles[i][j]=make_shared<Tile>(tiles[i][j]);
        }
        g->sceneHeight=sceneHeight;
        g->sceneWidth=sceneWidth;

        return g;

    }
    void build(int width, int height)
    {
        sceneWidth=width;
        sceneHeight=height;
        int sizeH=height/Tile::TILE_SIZE;
        int sizeW=width/Tile::TILE_SIZE;
        tiles.clear();

        tiles.resize(sizeH);
        for (int i = 0; i < sizeH; ++i)
        {
            tiles[i].resize(sizeW);
            for(int j=0;j<sizeW;++j)
                tiles[i][j]=make_shared<Tile>(j*Tile::TILE_SIZE,i*Tile::TILE_SIZE);
        }

    }

    int width() const
    {
        return tiles.front().size();
    }

    int height() const
    {
        return tiles.size();
    }



};

#endif // GRID_H
